package com.example.latch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sql.DataSource;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/21 下午10:22
 */
public class MysqlLatchUtils {

    static Logger logger = LoggerFactory.getLogger(MysqlLatchUtils.class.getName());

    public static void latchInAction(DataSource dataSource, MysqlLatchListener mysqlLatchListener) {
        MySqlSyncLatch mySqlSyncLatch = null;
        try {
            mySqlSyncLatch = new MySqlSyncLatch(dataSource, mysqlLatchListener);
            mySqlSyncLatch.start();
        } catch (Exception e) {
            logger.warn("latch error : {}", e.getMessage());
        } finally {
            if (mySqlSyncLatch != null) {
                mySqlSyncLatch.stop();
            }
        }
    }
}
